import { onBeforeUnmount, onMounted, reactive } from "vue"

export default function(node) {
  let mousePos = reactive({x: 0, y: 0})

  node = node || window

  function updateMousePos(event) {
    mousePos.x = event.pageX
    mousePos.y = event.pageY
    console.log('mouse:', event.pageX, 'X', event.pageY)
  }

  onMounted(()=>{
    node.addEventListener('click', updateMousePos)
  })

  onBeforeUnmount(()=>{
    node.removeEventListener('click', updateMousePos)
  })

  return mousePos
}